package com.s10.ecloud.web.action;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.s10.ecloud.web.Constants;
import com.s10.ecloud.web.model.PageModel;
import com.s10.ecloud.web.model.User;
import com.s10.ecloud.web.service.IDeviceService;

public class DeleteDeviceModelAction extends ActionSupport {
	@Resource
	private IDeviceService deviceService;

	@Action(value = "/deleteDeviceModel", results = { @Result(name = "success", location = "/page/ent/deviceModelListPage.jsp") })
	public String deleteDeviceModel() throws Exception {

		this.setPageModel();
		User currentUser = ((User) ActionContext.getContext().getSession()
				.get(Constants.SESSION_KEY_USER));

		String messgae = deviceService.deleteDeviceModel(this.getPager(),
				currentUser.getId(), this.getTargetId());// 查询PageMode

		if (messgae != null) {
			this.addActionMessage(messgae);
		}

		return this.SUCCESS;
	}

	public void setPageModel() {
		if (this.pager == null) {
			this.pager = new PageModel();
		}

		if (this.pager.getMaxPageItems() == 0) {
			this.pager.setMaxPageItems(10);
		}
	}

	private String functionCode;
	private int targetId;

	/**
	 * @return the targetId
	 */
	public int getTargetId() {
		return targetId;
	}

	/**
	 * @param targetId
	 *            the targetId to set
	 */
	public void setTargetId(int targetId) {
		this.targetId = targetId;
	}

	/**
	 * @return the functionCode
	 */
	public String getFunctionCode() {
		return functionCode;
	}

	/**
	 * @param functionCode
	 *            the functionCode to set
	 */
	public void setFunctionCode(String functionCode) {
		this.functionCode = functionCode;
	}

	private PageModel pager;

	/**
	 * @return the page
	 */
	public PageModel getPager() {
		return pager;
	}

	/**
	 * @param page
	 *            the page to set
	 */
	public void setPager(PageModel pager) {
		this.pager = pager;
	}
}
